Google News
logo
jQuery - Interview Questions
Explain the difference between jquery.size() and jquery.length?
In jquery both works and gives the same result but now the time in current version of jquery we use the jquery.length because jquery.size is depreciated.
 
Below is the some points about this properties :
 
jquery.size() and jquery.length() both returns the number of element in an object.
 
jquery.length() property is faster as compared to jquery.size() method.
 
jquery.length() property prefered compared to size() because it does not have overhead of a function call.
 
Very significant difference is that jquery.size() is depreciated so we always use jquery.length() instead of jquery.size().
 
For Examples: Counts the number of unordered list li on the page to demonstrate the same according to the jQuery documentation.
 
$('li').size();

$('li').length;// faster
 
Advertisement